package cn.liulin.java8.lambda;

/**
 * cn.liulin.java8.lambda$
 * Lambda表达式允许你直接以内联的形式为函数式接口的抽象方法提供实现，并把整个表达式作为函数式接口的实例（具体来说，
 * 是函数式接口一个具体实现的实例），等价于匿名内部类
 * @author ll
 * @date 2021-09-16 18:10:16
 **/
public class FunctionLambda {
    public static void main(String[] args) {
        runnable();
    }

    /**
     * 正常实现Runnable和Lambda实现Runnable
     * @author ll
     * @date 2021-09-16 18:14:33
     * @return void
     **/
    private static void runnable() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("正常实现Runnable");
            }
        };

        //Lambda实现
        Runnable lambdaRunnable = () -> System.out.println("Lambda实现Runnable");

        new Thread(runnable).start();
        new Thread(lambdaRunnable).start();

        process(runnable);
        process(lambdaRunnable);
        process(() -> System.out.println("Lambda实现Runnable2"));
    }

    private static void process(Runnable runnable) {
        runnable.run();
    }
}
